import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../common/routes.dart';
import '../model/cartoon_model.dart';
import '../utils/utils.dart';

class CartoonListItem extends StatelessWidget {
  final CartoonModel cartoon;

  const CartoonListItem({super.key, required this.cartoon});

  @override
  Widget build(BuildContext context) {
    var imageUrl = cartoon.avatar;
    if (cartoon.banner != null && cartoon.banner!.isNotEmpty) {
      imageUrl = cartoon.banner ?? "";
    }
    final useNum = Utils.formatNumber(cartoon.useNum ?? 0);
    final fansNum = Utils.formatNumber(cartoon.fansNum ?? 0);
    final num = "$useNum互动·$fansNum粉丝";

    return GestureDetector(
      onTap: () {
        Get.toNamed(Routes.CARTOON_INFO, arguments: {"cartoonId": cartoon.id});
      },
      child: Padding(
        padding: const EdgeInsets.fromLTRB(10, 8, 10, 8),
        child: Container(
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(16),
            boxShadow: const [
              BoxShadow(
                color: Color.fromRGBO(0, 0, 0, 0.06),
                blurRadius: 10,
                spreadRadius: 2,
              ),
            ],
            border: Border.all(
              color: const Color.fromRGBO(0, 0, 0, 0.1),
              width: 0.5,
            ),
          ),
          child: Padding(
            padding: const EdgeInsets.all(10),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                ClipRRect(
                  borderRadius: BorderRadius.circular(32),
                  child: CachedNetworkImage(
                    fit: BoxFit.cover,
                    fadeInDuration: const Duration(milliseconds: 100),
                    fadeOutDuration: const Duration(seconds: 0),
                    imageUrl: imageUrl,
                    width: 64,
                    height: 64,
                  ),
                ),
                const SizedBox(width: 10),
                Expanded(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(cartoon.name, style: const TextStyle(fontSize: 15, fontWeight: FontWeight.bold)),
                      if (cartoon.user != null) Text("@${cartoon.user?.nickname ?? ""}", style: const TextStyle(color: Colors.black45)),
                      Text(cartoon.summary, maxLines: 3, overflow: TextOverflow.ellipsis),
                      const SizedBox(height: 5),
                      Text(num, style: const TextStyle(color: Colors.black45))
                    ],
                  ),
                ),
              ],
            ),
          ), // Add child widget here
        ),
      ),
    );
  }
}
